package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.impl.DishServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理")
@Slf4j
public class PageController {
    @Autowired
    private DishService dishService;
    @GetMapping("/page")
    @ApiOperation("菜品列表")
    public Result<PageResult> page(DishPageQueryDTO pageQueryDTO){
        System.out.println("pageQueryDTO = " + pageQueryDTO);
        Result<PageResult> all = dishService.findAll(pageQueryDTO);
        System.out.println(all);
        return all;
    }

    @PostMapping("")
    @ApiOperation("新增菜品")
    public Result<String> save(@RequestBody Dish dish){
        System.out.println("dish = " + dish);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("菜品状态")
    public Result<String> status(@PathVariable("status") Integer status, @RequestParam("id") int id){
        dishService.status(status,id);
        return Result.success();
    }

    @DeleteMapping("")
    @ApiOperation("删除菜品")
    public Result<String> delete(@RequestParam("ids") List<Integer> ids){
        log.info("ids = {}",ids);
        dishService.delete(ids);
        return Result.success();
    }
}
